package org.delphy.indy2.containers.carbonPanelClasses
{
	import mx.containers.Canvas;
	
	import org.delphy.indy2.core.ICarbonComponent;
	import org.delphy.indy2.layers.FilterLayer;

	//--------------------------------------
	//  Styles
	//
	//  NOTE: Any corner-radius related variables MUST be no smaller than 1! 
	//  You will not get what you expects if such styles are set to zero.
	//--------------------------------------
	
	/**
	*	Thickness of the border
	*	
	*	@default 1
	*/
	[Style(name="weight", type="Number", format="Length", inherit="no")]
	
	/**
	*	Top-left corner radius
	*	
	*	@default 12
	*/
	[Style(name="topLeftRadius", type="Number", format="Length", inherit="no")]

	/**
	*	Top-right corner radius
	*	
	*	@default 12
	*/
	[Style(name="topRightRadius", type="Number", format="Length", inherit="no")]
	
	/**
	*	Bottom-left corner radius
	*	
	*	@default 1
	*/
	[Style(name="bottomLeftRadius", type="Number", format="Length", inherit="no")]

	/**
	*	Bottom-right corner radius
	*	
	*	@default 1
	*/
	[Style(name="bottomRightRadius", type="Number", format="Length", inherit="no")]
	 
	public class CarbonBorder extends Canvas implements ICarbonBorder, ICarbonComponent
	{

		//--------------------------------------
		//  Variables
		//--------------------------------------
		
		/**
		 *	@protected
		 *	Default weight
		 *	
		 *	@default 1
		 */
		protected var _weight:Number=1;
		
		/**
		 *	@protected
		 *	Default top-left corner radius
		 *	
		 *	@default 12
		 */
		protected var _topLeftRadius:Number=12;
		
		/**
		 *	@protected
		 *	Default top-right corner radius
		 *	
		 *	@default 12
		 */
		protected var _topRightRadius:Number=12;
		
		/**
		 *	@protected
		 *	Default bottom-left corner radius
		 *	
		 *	@default 1
		 */
		protected var _bottomLeftRadius:Number=1;
		
		/**
		 *	@protected
		 *	Default bottom-right corner radius
		 *	
		 *	@default 1
		 */
		protected var _bottomRightRadius:Number=1;

		//--------------------------------------
		//  Implenmentation of ICarbonComponent
		//--------------------------------------
		/**
		 * @public
		 */
		public function get defaultStyleName():String{
			return "carbonPanelBorder";
		}
		
		//--------------------------------------
		//  Implenmentation of ICarbonBorder
		//--------------------------------------
		
		/**
		 *	@public
		 */
		public function get weight():Number{
			return getStyle("weight") ? getStyle("weight") : _weight;
		}
		
		/**
		 *	@public
		 */
		public function get topLeftRadius():Number{
			return getStyle("topLeftRadius") ? getStyle("topLeftRadius") : _topLeftRadius;
		}
		
		/**
		 *	@public
		 */
		public function get topRightRadius():Number{
			return getStyle("topRightRadius") ? getStyle("topRightRadius") : _topRightRadius;
		}
		
		/**
		 *	@public
		 */
		public function get bottomLeftRadius():Number{
			return getStyle("bottomLeftRadius") ? getStyle("bottomLeftRadius") : _bottomLeftRadius;
		}
		
		/**
		 *	@public
		 */
		public function get bottomRightRadius():Number{
			return getStyle("bottomRightRadius") ? getStyle("bottomRightRadius") : _bottomRightRadius;
		}

		/**
		 *	@public
		 */
	    public function showHighlight():void{
	    	filterLayer.enableFilters();
	    }

		/**
		 *	@public
		 */       
	    public function hideHighlight():void{
	    	filterLayer.disableFilters();
	    }

		/**
		 *	@public
		 */       
	    public function playResizingAnimation():void{
       
	    }

		/**
		 *	@public
		 */       
	    public function stopResizingAnimation():void{
       
	    }
		 				
		//--------------------------------------
		//  Filters
		//--------------------------------------
	
		/**
		 * @protected
		 * Outter side filter layer
		 */
		 protected var filterLayer:FilterLayer;
				
		public function CarbonBorder()
		{
			super();			
		}
		
		//--------------------------------------
		//  Overridden methods
		//--------------------------------------
		
		override protected function createChildren():void{
			super.createChildren();
			
			// Fallback to default style if no styleName specified
			if(!styleName)
				styleName="carbonPanelBorder";			

			filterLayer=new FilterLayer(this);
			filterLayer.setStyle("topLeftRadius", topLeftRadius);
			filterLayer.setStyle("topRightRadius", topRightRadius);
			filterLayer.setStyle("bottomLeftRadius", bottomLeftRadius);
			filterLayer.setStyle("bottomRightRadius", bottomRightRadius);
			filterLayer.disableFilters();
			
			rawChildren.addChild(filterLayer);
		}
				
	}
}